package com.security;

import com.pojo.vo.UserVo;
import com.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class AuthenticationProxyLocal implements AuthenticationProxy {
    @Autowired
    UserService userService;
    @Autowired
    OtpService otpService;

    @Override
    public boolean sendAuth(String username, String password) {
        //1.调用认证服务器进行认证
        boolean auth = userService.auth(username, password);
//        //2.生成并发送otp
//        if(auth){
//            otpService.sendOtp(username);
//            return true;
//        }
        //登陆成功发送令牌

        return auth;
    }

    @Override
    public boolean checkOtp(String username, String code) {
        return otpService.checkOtp(username, code);
    }

    @Override
    public UserVo load(String username) {
        return (UserVo) userService.loadUserByUsername(username);
    }
}
